<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\widgets\LinkPager;
use kartik\editable\Editable;

$this->title = Yii::t('app.order', '分配房号');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="order-room-list">

    <h2 class="page-header"><small><?= $product->name?> - <?= $product->code ?> - <?= Html::encode($this->title) ?></small>
		
        <?=
			($type ==1) ? 
			
				Html::a('切换至房型模式', ['list', 'product_id'=>$product->id, 'type'=>2], ['class' => 'btn btn-success btn-sm pull-right'])
				:
				Html::a('切换至订单模式', ['list', 'product_id'=>$product->id, 'type'=>1], ['class' => 'btn btn-info btn-sm pull-right']) ?>

	</h2>
		<!-- label class="pull-right"><input type="checkbox" name="change-room"  >&nbsp;未分配</label -->

	<table class="table table-striped">

		<thead><tr><th>订单号</th><th>房型</th> <th>入住人数</th> <th>创建人</th> <th>房间号</th> </tr></thead>

		<?php foreach($model as $room){ ?>
			<tr>
				<td><?= $room->order['code'] ?></td>
				<td>
					<?php
						if($product->stock == 1){ // 国内航线

							echo "<p>";
            				echo $room->productRoom->room->name;
            				echo '  '.$room->productRoom->room->code;
            				echo '  '.$room->productRoom->people .'人间&nbsp;&nbsp;';
							echo "</p>";
						}elseif($product->stock == 2){ // 海外航线

							$t = json_decode($product->rooms, true);

							echo "<p>";
            				print_r($t[$room->room_id]['name']);
							echo "</p>";
						}
					?>
				</td>
				<td><?= $room->num ?></td>
				<td><?= isset($room->member->id) ? $room->member->profile->name : '(未设置)'  ?></td>
				<td>
    				<?php echo Editable::widget([
    				    'name' => 'code',
						'value' => $room->code,
    				    'asPopover' => true,
    				    'header' => '分配房号',
    				    'size'=>'sm',
    				    'formOptions' => ['action'=>'/order/room/edit-code?id='.$room->id,'method'=>'get'],
    				    'options' => ['class'=>'form-control', 'placeholder'=>'请输入房号'],
    				]);?>
				</td>
			</tr>
		<?php } ?>

	</table>
	<!-- ?= LinkPager::widget(['pagination' => $pages]); ? -->

</div>
